package _4_rpc教程

import (
	"fmt"
	"net/rpc"
)

func main() {
	//1、rpc连接服务
	conn, err := rpc.Dial("tcp", "127.0.0.1:8802")
	if err != nil {
		fmt.Println("rpc连接服务失败：", err)
		return
	}
	defer conn.Close()

	//2、调用远程函数
	var reply string //接收函数返回值
	err = conn.Call("Hello.HelloWord", "李白", &reply)
	if err != nil {
		fmt.Println("远程函数调用失败!", err)
		return
	}
	fmt.Println(reply)

	//1.1rpc连接服务使用自定义rpc封装
	connl := Initclient("127.0.0.1:8802")
	var replay string
	errl := connl.HelloWord("杜甫", &replay)
	if errl != nil {
		fmt.Println("封装调用失败...", errl)
	}
	fmt.Println(replay, errl)
}
